package com.rongshu.view.login.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetBean;
import com.rongshu.view.login.contract.BindMobileView;
import com.rongshu.view.login.entity.VerificationCode;

import rx.Subscriber;
import rx.functions.Action0;

public class BindMobilePresenter extends BasePresenter<BindMobileView> {

    public BindMobilePresenter(Context context) {
        super(context);
    }

    /**
     * 绑定手机号码
     */
    public void getBindingMobile(int user_id, String mobile, String sms_code, String key, String sign) {
        RetorfitService.getBindingMobile(user_id, mobile, sms_code, key, sign)
                .subscribe(new Subscriber<INetBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(INetBean bean) {
                        if (getView() != null) {
                            getView().onBindPhone(bean);
                        }
                    }
                });
    }

    /**
     * 获取手机验证码
     *
     * @param mobile
     * @param type
     * @param sign
     */
    public void getPhoneVerficationCode(String mobile, int type, String sign) {
        RetorfitService.getPhoneVerficationCode(mobile, type, sign)
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {

                    }
                })
                .subscribe(new Subscriber<VerificationCode>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                    }

                    @Override
                    public void onNext(VerificationCode verificationCode) {
                        if (getView() != null) {
                            getView().getVerificationResult(verificationCode);
                        }
                    }
                });
    }

}
